package basic_syntax

/**
 * Return null if str does not hold an integer:
 */
fun parseInt(str: String): Int? {
    // ...
    return str.length
}

/**
 * Use a function returning nullable value:
 */
fun printProduct(arg1: String, arg2: String) {
    val x = parseInt(arg1)
    val y = parseInt(arg2)

    // Using `x * y` yields error because they may hold nulls.
    if (x != null && y != null) {
        // x and y are automatically cast to non-nullable after null check
        println(x * y)
    } else {
        println("either '$arg1' or '$arg2' is not a number")
    }
}


